//
//  HBHMainViewController.m
//  HubeiHotel
//
//  Created by 张露杰 on 17/11/13.
//  Copyright © 2017年 张露杰. All rights reserved.
//

#import "HBHMainViewController.h"
#import "HBHMainSearchViewController.h"
#import <SDCycleScrollView.h>
#import "scrollVCell.h"
#import "HBHMainIconCell.h"
#import "HBHMainInformationCell.h"
#import "HBHMainFourthCell.h"
#import "HBHMainResumeCell.h"
#import "HBHMainBusinessCell.h"
#import "HBHMainHotelCell.h"
#import "JiuDianViewController.h"
#import "CerterViewController.h"
#import "CerterViewController.h"
#import "MianScrollVViewController.h"
#import "ZhaoPinViewController.h"
#import "WokerViewController.h"
#import "TLCityPickerController.h"
#import "DetailJiuDianViewController.h"
#import "AllKindViewController.h"
#import "FindCell.h"
#import "JiuDianCell.h"

#import "HBHFindDetailViewController.h"
#import "AllScrollVViewController.h"
#import "HBHBannerViewController.h"
#import "HBHZhixunViewController.h"
#import "HBHeadView.h"
@interface HBHMainViewController ()<HWDNavHeadViewDelegate,UITableViewDelegate,UITableViewDataSource,TLCityPickerDelegate,SDCycleScrollViewDelegate,BMKLocationServiceDelegate,BMKRouteSearchDelegate>

@property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) NSMutableArray *btnArr;

@property (nonatomic, strong) NSMutableArray *lunBoArr;//轮播数组
@property (nonatomic, strong) NSMutableArray *ziXunArr;//资讯数组
@property (nonatomic, strong) NSMutableArray *zhaoPinArr;//招聘数组
@property (nonatomic, strong) NSMutableArray *ShangJiaArr;//商家数组
@property (nonatomic, strong) NSMutableArray *youHuiArr;//优惠数组

@property (nonatomic, strong) NSMutableArray *btnThreeArr;

@property (nonatomic, strong) NSString *cityName;
@property (nonatomic, strong) NSString *cityID;

/**
 定位类
 */
@property (nonatomic, strong) BMKLocationService *locService;

/**
 用户位置
 */
@property (nonatomic, strong) BMKUserLocation *userLocation;

@end

@implementation HBHMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //初始化数据
    _btnArr = [NSMutableArray new];
    _lunBoArr = [NSMutableArray new];
    _ziXunArr = [NSMutableArray new];
    _zhaoPinArr = [NSMutableArray new];
    _ShangJiaArr = [NSMutableArray new];
    _youHuiArr = [NSMutableArray new];
    _btnThreeArr = [NSMutableArray new];
    
    [self creatView];
    [self creatHeadView];
    [self getRequest];
}

-(void)getRequest
{
    [self addLunBoRequest];
    [self getIcon];
    [self addZiXunRequest];
    [self addZhaoPinRequest];
    [self getFindInfoBeanList];
    [self.locService startUserLocationService];
}

-(void)creatView
{
    _cityName = [standfault objectForKey:@"cityName"];
    _cityID = [standfault objectForKey:@"cityID"];
    if (!_cityName) {
        _cityName = @"武汉市";
        [standfault setObject:_cityName forKey:@"cityName"];
        [standfault synchronize];
    }
    if (!_cityID) {
        _cityID = @"420100";

        [standfault setObject:_cityID forKey:@"cityID"];
        [standfault synchronize];
    }
    
    [self creatLeftBarButtonWithCity:_cityName];
    [self.view addSubview:self.table];
}

#pragma Mark Request
-(void)addLunBoRequest//轮播请求
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [HttpRequest PostrequestUrl:@"/banner/list" Dic:
         @{@"type":@"",
           @"adCode":_cityID,
           @"isDisplay":@"0",//是否显示(0=否，1=是)
           } completion:^(NSDictionary *responseDic) {
               dispatch_async(dispatch_get_main_queue(), ^{
                   if ([responseDic[@"success"] boolValue]) {
                       _lunBoArr = [NSMutableArray arrayWithArray:responseDic[@"data"]];
                       
                       [self creatHeadView];
                       
                   }
                   if ([_table.mj_header isRefreshing]) {
                       [_table.mj_header endRefreshing];
                   }
               });
           }];
    });
}

-(void)getIcon
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [HttpRequest PostrequestUrl:@"/other/classificationBeanList" Dic:@{@"type":@"1"} completion:^(NSDictionary *responseDic) {
            dispatch_async(dispatch_get_main_queue(), ^{
                if ([responseDic[@"success"] boolValue]) {
                    [_btnArr removeAllObjects];
                    _btnArr = responseDic[@"data"];
                    if (_btnArr.count > 0) {
                        NSMutableDictionary *dic = [NSMutableDictionary new];
                        [dic setValue:@"" forKey:@"image"];
                        [dic setValue:@"全部" forKey:@"name"];
                        [dic setValue:@"9" forKey:@"id"];
                        if (_btnArr) {
                            for (int i = 0; i<3; i++) {
                                [_btnThreeArr addObject:_btnArr[_btnArr.count - 1]];
                                [_btnArr removeObjectAtIndex:_btnArr.count - 1];
                            }
                            [_btnArr addObject:dic];
                        }
                    }
                    
                    [self creatHeadView];
                }
                if ([_table.mj_header isRefreshing]) {
                    [_table.mj_header endRefreshing];
                }
            });
        }];
    });
}

-(void)addZiXunRequest{//资讯请求
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [HttpRequest PostrequestUrl:@"/information/list" Dic:
         @{@"type":@"0",
           @"adCode":_cityID,//[ToolViewVC getNotNullStr:[standfault objectForKey:@"adCode"]]
           @"isHeadlines":@"1"
           } completion:^(NSDictionary *responseDic) {
               dispatch_async(dispatch_get_main_queue(), ^{
                   if ([responseDic[@"success"] boolValue]) {
                       //                       [_ziXunArr removeAllObjects];
                       //                       NSArray *ziArr = [[NSArray alloc]initWithArray:responseDic[@"data"]];
                       //                       for (int i = 0; i<[ziArr count]; i++) {
                       //                           [_ziXunArr addObject:ziArr[i][@"title"]];
                       //                       }
                       
                       _ziXunArr = [NSMutableArray arrayWithArray:responseDic[@"data"]];
     
                       [self creatHeadView];
                   }
                   if ([_table.mj_header isRefreshing]) {
                       [_table.mj_header endRefreshing];
                   }
               });
           }];
    });
}

-(void)addZhaoPinRequest{//招聘列表请求
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [HttpRequest PostrequestUrl:@"/recruit/positionList" Dic:
         @{@"area":@"",//[ToolViewVC getNotNullStr:[standfault objectForKey:@"adCode"]]
           @"pageNo":@"1",
           @"pageSize":@"3",
           @"city":_cityID
           } completion:^(NSDictionary *responseDic) {
               dispatch_async(dispatch_get_main_queue(), ^{
                   
                   if ([responseDic[@"success"] boolValue]) {
                       _zhaoPinArr = responseDic[@"data"];
                       //刷新第一行
                       [_table reloadData];
                   }
                   if ([_table.mj_header isRefreshing]) {
                       [_table.mj_header endRefreshing];
                   }
               });
           }];
    });
}

-(void)addShangJiaRequest{//商家请求
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [HttpRequest PostrequestUrl:@"/business/businessBeanList" Dic:
         @{@"classification.id":@"",
           @"longitude":[NSString stringWithFormat:@"%lf",_userLocation.location.coordinate.longitude],
           @"latitude":[NSString stringWithFormat:@"%lf",_userLocation.location.coordinate.latitude],
           @"orderBy":@"",
           @"distance":@"",
           @"pageNo":@"1",
           @"pageSize":@"3",
           @"city.id":_cityID
           } completion:^(NSDictionary *responseDic) {
               dispatch_async(dispatch_get_main_queue(), ^{
                   if ([responseDic[@"success"] boolValue]) {
                       _youHuiArr = responseDic[@"data"];
                       //刷新第一行
                       [_table reloadData];
                   }
                   if ([_table.mj_header isRefreshing]) {
                       [_table.mj_header endRefreshing];
                   }
               });
           }];
    });
}

-(void)getFindInfoBeanList
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [HttpRequest PostrequestUrl:@"/find/findInfoBeanList" Dic:@{@"pageNo":@"1",@"pageSize":@"3",@"twoKinds.id":@"",@"oneKinds.id":@"0c458b1ba61d45b98110a00730a07993",@"adCode":_cityID} completion:^(NSDictionary *responseDic) {
            dispatch_async(dispatch_get_main_queue(), ^{
                if ([responseDic[@"success"] boolValue]) {
                    _ShangJiaArr = responseDic[@"data"];
                    //刷新第一行
                    [_table reloadData];
                }
                if ([_table.mj_header isRefreshing]) {
                    [_table.mj_header endRefreshing];
                }
            });
        }];
    });
}

#pragma mark - BMKLocationService
-(BMKLocationService *)locService
{
    if (!_locService) {
        _locService = [[BMKLocationService alloc]init];
        _locService.delegate = self;
    }
    return _locService;
}

/**
 *用户位置更新后，会调用此函数
 *@param userLocation 新的用户位置
 */
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
    _userLocation = userLocation;
    if (_userLocation) {
        [self.locService stopUserLocationService];
        [self addShangJiaRequest];
    }
}

/**
 *定位失败后，会调用此函数
 *@param error 错误号，参考CLError.h中定义的错误号
 */
- (void)didFailToLocateUserWithError:(NSError *)error
{
    NSLog(@"location error");
}

//导航栏创建
-(void)creatLeftBarButtonWithCity:(NSString *)city
{
    UILabel *cityLabel = [TomamaUI createLabel:CGRectMake(0, 0, [TomamaUI getStringWeithtWith:city andHeigth:17*screenW_6 andFont:[UIFont systemFontOfSize:17*screenW_6]], 17*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:17*screenW_6] textColor:TextWhite text:city];
//    if (cityLabel.frame.size.width > [TomamaUI getStringWeithtWith:city andHeigth:17*screenW_6 andFont:[UIFont systemFontOfSize:17*screenW_6]]) {
//        cityLabel.frame = CGRectMake(0, 0, [TomamaUI getStringWeithtWith:city andHeigth:17*screenW_6 andFont:[UIFont systemFontOfSize:17*screenW_6]], 17*screenW_6);
//    }
    cityLabel.center = CGPointMake(cityLabel.center.x , 22);
    UIImageView *icon = [TomamaUI createImageView:CGRectMake(CGRectGetMaxX(cityLabel.frame) + 5*screenW_6, 0, 7.5*screenW_6, 5*screenW_6) backGroundImageV:@"Main_down"];
    icon.center = CGPointMake(icon.center.x, cityLabel.center.y);
    
    UIView *view =[[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(icon.frame), 44)];
    [view addSubview:cityLabel];
    [view addSubview:icon];
    
    UITapGestureRecognizer *lefttap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(leftTap)];
    [view addGestureRecognizer:lefttap];
    
    UIBarButtonItem *barButtonitem = [[UIBarButtonItem alloc] initWithCustomView:view];
    self.navigationItem.leftBarButtonItem = barButtonitem;
    
    UIButton *btn = [TomamaUI createButton:0 Frame:CGRectMake(0, 0, SCREENW - view.frame.size.width, 31.5*screenW_6) targ:self sel:@selector(goToSearch) titleColor:nil font:nil title:nil image:nil backGroundImage:nil];
    btn.backgroundColor = TextWhite;
    self.navigationItem.titleView = btn;
    btn.layer.masksToBounds = YES;
    btn.layer.cornerRadius = 3;
    
    UILabel *label = [TomamaUI createLabel:CGRectMake(13*screenW_6, 0, 200*screenW_6, 14*screenW_6) textAligment:0 font:[UIFont systemFontOfSize:14*screenW_6] textColor:[UIColor colorWithHexString:@"#bababa"] text:@"输入关键字搜索"];
    [btn addSubview:label];
    UIImageView *imageV = [TomamaUI createImageView:CGRectMake(btn.frame.size.width - 55*screenW_6, 0, 16*screenW_6, 16*screenW_6) backGroundImageV:@"Main_search"];
    [btn addSubview:imageV];
    label.center = CGPointMake(label.center.x, btn.frame.size.height/2);
    imageV.center = CGPointMake(imageV.center.x, btn.frame.size.height/2);
}

-(UITableView *)table//创建tableView
{
    if (!_table) {
        _table = [[UITableView alloc]initWithFrame:CGRectMake(0,0, SCREENW, SCREENH-64) style:UITableViewStyleGrouped];
        _table.delegate = self;
        _table.dataSource = self;
        _table.showsHorizontalScrollIndicator = NO;
        _table.showsVerticalScrollIndicator = NO;
        _table.separatorStyle = 0;
        _table.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
        _table.backgroundColor = [UIColor clearColor];
        _table.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
            [self getRequest];
        }];
    }
    return _table;
}

- (void)creatHeadView
{
    NSMutableArray *images = [NSMutableArray new];
    for (int i = 0; i<[_lunBoArr count]; i++) {
        [images addObject:_lunBoArr[i][@"image"]];
    }
    NSMutableArray *arr = [NSMutableArray new];
    for (int i = 0; i<[_ziXunArr count]; i++) {
        [arr addObject:_ziXunArr[i][@"title"]];
    }

    HBHeadView *headView = [[HBHeadView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 596*screenW_6) bannerImages:images dataArray:_btnArr zhiArray:arr];
    headView.backgroundColor = [UIColor whiteColor];
    headView.bannerblock = ^(NSInteger index){
        HBHBannerViewController *vc = [HBHBannerViewController new];
        vc.bannerId = self.lunBoArr[index][@"id"];
        [self.navigationController pushViewController:vc animated:YES];
    };
    headView.datablock = ^(NSInteger index) {
        [self goBtnVC:index];
    };
    headView.zhiblock = ^(NSInteger index) {
        HBHZhixunViewController *vc = [HBHZhixunViewController new];
        vc.zhixunId = self.ziXunArr[index][@"id"];
        [self.navigationController pushViewController:vc animated:YES];
    };
    headView.imageblock = ^(NSInteger index) {
        MianScrollVViewController *VC = [MianScrollVViewController new];
        [self.navigationController pushViewController:VC animated:YES];
    };
    headView.iconblock = ^(NSInteger index) {
        if (_btnThreeArr.count == 0) {
            [TomamaUI creatAlertWithTarget:self message:@"暂时无数据" timeInterval:2.0];
        }else{
            JiuDianViewController *vc = [JiuDianViewController new];
            
            switch (index) {
                case 0:
                    vc.typeDic = _btnThreeArr[1];
                    break;
                    
                case 1:
                    vc.typeDic = _btnThreeArr[2];
                    break;
                    
                case 2:
                    vc.typeDic = _btnThreeArr[0];
                    break;
                    
                default:
                    break;
            }
            vc.typeThree = 1;
            vc.cityName = _cityName;
            vc.cityID = _cityID;
            [self.navigationController pushViewController:vc animated:YES];
            vc.JiuDianBlock = ^(NSString *cityName, NSString *cityID) {
                _cityName = cityName;
                _cityID = cityID;
                [self creatLeftBarButtonWithCity:_cityName];
                [self addLunBoRequest];
                [self addZiXunRequest];
                [self addZhaoPinRequest];
                [self addShangJiaRequest];
                [self getFindInfoBeanList];
            };
        }
    };
    [_table setTableHeaderView:headView];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 31*screenW_6)];
    view.backgroundColor = [UIColor whiteColor];
    
    NSString *imageName = @"";
    NSString *title = @"";
    if (section == 0) {
        imageName = @"Main_titleBack1";
        title = @"求职招聘";
    }else if (section == 1){
        imageName = @"Main_titleBack2";
        title = @"招商天地";
    }else if (section == 2){
        imageName = @"Main_titleBack3";
        title = @"优惠折扣";
    }
    UIImageView *imageV = [TomamaUI createImageView:CGRectMake(0, 0, 130*screenW_6, 31*screenW_6) backGroundImageV:imageName];
    [view addSubview:imageV];
    imageV.center = CGPointMake(view.frame.size.width/2, view.frame.size.height/2);
    
    UILabel *label = [TomamaUI createLabel:CGRectMake(0, 0, SCREENW, 13*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:13*screenW_6] textColor:TextWhite text:title];
    [view addSubview:label];
    label.center = CGPointMake(view.frame.size.width/2, view.frame.size.height/2);
    
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 31*screenW_6;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 0)];
    view.userInteractionEnabled = YES;
    view.tag = section;
    
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 38*screenW_6)];
    backView.backgroundColor = [UIColor whiteColor];
    [view addSubview:backView];
    
    NSString *more = @"查看更多";
    UILabel *moreLabel = [TomamaUI createLabel:CGRectMake(0, 0, [TomamaUI getStringWeithtWith:more andHeigth:38*screenW_6 andFont:[UIFont systemFontOfSize:13*screenW_6]], 38*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:13*screenW_6] textColor:TextGray text:more];
    [view addSubview:moreLabel];
    moreLabel.center = CGPointMake((SCREENW - 9*screenW_6)/2, 19*screenW_6);
    
    UIImageView *icon = [TomamaUI createImageView:CGRectMake(CGRectGetMaxX(moreLabel.frame) + 3*screenW_6, 0, 6*screenW_6, 10*screenW_6) backGroundImageV:@"right"];
    [view addSubview:icon];
    icon.center = CGPointMake(icon.center.x, moreLabel.center.y);
    //添加点击
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(footTap:)];
    [view addGestureRecognizer:tap];
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 53*screenW_6;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)//招聘
    {
        return _zhaoPinArr.count;
    }else if (section == 1)//商家
    {
        return _ShangJiaArr.count;
    }else{
        return _youHuiArr.count;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0){//求职招聘
        HBHMainResumeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HBHMainResumeCell"];
        if (!cell) {
            cell = [[HBHMainResumeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HBHMainResumeCell"];
        }
        if (indexPath.section == 0) {
            if (_zhaoPinArr.count>0) {
                [cell loadCellWithData:_zhaoPinArr[indexPath.row]];
            }
        }
        return cell;
    }else if (indexPath.section == 1){//招商天地
        FindCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FindCell"];
        if (!cell) {
            cell = [[FindCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FindCell"];
        }
        if (_ShangJiaArr.count>0) {
            [cell setDataDic:_ShangJiaArr[indexPath.row]];
        }
        return cell;
    }else{//折扣优惠
        JiuDianCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JiuDianCell"];
        if (!cell) {
            cell = [[JiuDianCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"JiuDianCell"];
        }
        [cell loadCellWithData:_youHuiArr[indexPath.row]];
        return cell;
    }
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0){
        return 108*screenW_6;
    }else if (indexPath.section == 1){
        return 115*screenW_6;
    }else if (indexPath.section == 2){
        return 160*screenW_6;
    }
    return 0;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)//招聘
    {
        WokerViewController *vc = [WokerViewController new];
        vc.wordId = _zhaoPinArr[indexPath.row][@"id"];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.section == 1)//招商天地
    {
        HBHFindDetailViewController *vc = [HBHFindDetailViewController new];
        vc.detailId = _ShangJiaArr[indexPath.row][@"id"];
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (indexPath.section == 2)//优惠折扣
    {
        if (![Storage isLogin]) {
            [Storage goToLogin];
        }else{
            DetailJiuDianViewController *vc = [DetailJiuDianViewController new];
            vc.hotelId = _youHuiArr[indexPath.row][@"id"];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}

//主按钮的跳转事件
-(void)goBtnVC:(NSInteger)tagNumber
{
    if (tagNumber == _btnArr.count - 1)//全部
    {
        AllKindViewController *vc = [AllKindViewController new];
        vc.cityName = _cityName;
        vc.cityID = _cityID;
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        JiuDianViewController *vc = [JiuDianViewController new];
        vc.typeDic = _btnArr[tagNumber];
        vc.cityName = _cityName;
        vc.cityID = _cityID;
        [self.navigationController pushViewController:vc animated:YES];
        vc.JiuDianBlock = ^(NSString *cityName, NSString *cityID) {
            _cityName = cityName;
            _cityID = cityID;
            [self creatLeftBarButtonWithCity:_cityName];
            [self addLunBoRequest];
            [self addZiXunRequest];
            [self addZhaoPinRequest];
            [self addShangJiaRequest];
            [self getFindInfoBeanList];
        };
    }
}

-(void)goToSearch//去搜索
{
    HBHMainSearchViewController *vc = [[HBHMainSearchViewController alloc]init];
    [self.navigationController pushViewController:vc animated:NO];
}

//查看更多点击事件
-(void)footTap:(UITapGestureRecognizer *)tap
{
    if (tap.view.tag == 1) {//求职招聘
        [self.navigationController pushViewController:[ZhaoPinViewController new] animated:YES];
    }else if (tap.view.tag == 2) {//招商天地
        AllScrollVViewController *hotVC = [AllScrollVViewController new];
        hotVC.parentId = @"0c458b1ba61d45b98110a00730a07993";
        hotVC.titleStr = @"招商天地";
        [self.navigationController pushViewController:hotVC animated:YES];
    }else if (tap.view.tag == 3) {//优惠折扣
        
    }
}

-(void)leftTap//省市区选择
{
    TLCityPickerController *cityPickerVC = [[TLCityPickerController alloc] init];
    [cityPickerVC setDelegate:self];
    //    cityPickerVC.loactionCityName = _cityDW;//定位的城市名
    //    cityPickerVC.commonCitys  // 最近访问城市，如果不设置，将自动管理
    cityPickerVC.hotCitys = @[@"武汉市", @"襄阳市", @"黄冈市"];//热门城市
    [self presentViewController:[[UINavigationController alloc] initWithRootViewController:cityPickerVC] animated:YES completion:^{
    }];
}


#pragma mark - TLCityPickerDelegate
- (void) cityPickerController:(TLCityPickerController *)cityPickerViewController didSelectCity:(NSString *)city didSelectCityID:(NSString *)ID
{
    //城市选择的跳转 选择的回调
    [cityPickerViewController dismissViewControllerAnimated:YES completion:^{
        _cityName = city;
        _cityID = ID;
        [self creatLeftBarButtonWithCity:_cityName];
        
        [self addLunBoRequest];
        [self addZiXunRequest];
        [self addZhaoPinRequest];
        [self addShangJiaRequest];
        [self getFindInfoBeanList];
        
        [standfault setObject:city forKey:@"cityName"];
        [standfault setObject:ID forKey:@"cityID"];
        [standfault synchronize];
    }];
}

- (void) cityPickerControllerDidCancel:(TLCityPickerController *)cityPickerViewController
{
    //取消的回调
    [cityPickerViewController dismissViewControllerAnimated:YES completion:^{
    }];
}

-(void)ShowRightCityName:(NSString *)cityStr
{
    //右边按钮展示(重新计算以免三角图片消失或位置不对)
    //    float width = [ToolViewVC getWidthFromString:cityStr Font:16*screenW_6];
    //    _rightBtn.frame = CGRectMake(_rightBtn.frame.origin.x,_rightBtn.frame.origin.y,width+30, 35);
    //    [_rightBtn setTitle:cityStr forState:UIControlStateNormal];
    //    [_rightBtn setImageEdgeInsets:UIEdgeInsetsMake(15,width+15,15,5)];
    //    [_rightBtn setTitleEdgeInsets:UIEdgeInsetsMake(5,5,5,15)];
}

@end
